Improve how to list Heroku specific gems

Akinori MUSHA 9 years ago
parent
commit
067dde298c
1 changed files with 16 additions and 8 deletions
  1. 16 8
      Gemfile

+ 16 - 8
Gemfile

@@ -125,15 +125,23 @@ gem 'tzinfo', '>= 1.2.0'	# required by rails; 1.2.0 has support for *BSD and Sol
125 125
 # Windows does not have zoneinfo files, so bundle the tzinfo-data gem.
126 126
 gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
127 127
 
128
-# This hack needs some explanation.  When on Heroku, use the pg, unicorn, and rails12factor gems.
129
-# When not on Heroku, we still want our Gemfile.lock to include these gems, so we scope them to
130
-# an unsupported platform.
131
-if ENV['ON_HEROKU'] || ENV['HEROKU_POSTGRESQL_ROSE_URL'] || ENV['HEROKU_POSTGRESQL_GOLD_URL'] || File.read(File.join(File.dirname(__FILE__), 'Procfile')) =~ /intended for Heroku/
128
+# Introduces a scope for Heroku specific gems.
129
+def on_heroku
130
+  if ENV['ON_HEROKU'] ||
131
+     ENV['HEROKU_POSTGRESQL_ROSE_URL'] ||
132
+     ENV['HEROKU_POSTGRESQL_GOLD_URL'] ||
133
+     File.read(File.join(File.dirname(__FILE__), 'Procfile')) =~ /intended for Heroku/
134
+    yield
135
+  else
136
+    # When not on Heroku, we still want our Gemfile.lock to include
137
+    # Heroku specific gems, so we scope them to an unsupported
138
+    # platform.
139
+    platform :ruby_18, &proc
140
+  end
141
+end
142
+
143
+on_heroku do
132 144
   gem 'pg'
133 145
   gem 'unicorn'
134 146
   gem 'rails_12factor', group: :production
135
-else
136
-  gem 'pg', platform: :ruby_18
137
-  gem 'unicorn', platform: :ruby_18
138
-  gem 'rails_12factor', platform: :ruby_18
139 147
 end